package com.chuqiyun.authorization.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chuqiyun.authorization.annotation.ApiCheck;
import com.chuqiyun.authorization.entity.Commodity;
import com.chuqiyun.authorization.service.CommodityService;
import com.chuqiyun.authorization.utils.ResponseResult;
import com.chuqiyun.authorization.utils.exception.UnauthorizedException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author mryunqi
 * @date 2023/4/22
 */
@RestController
public class UserCommodityController {

    @Resource
    private CommodityService commodityService;

    /**
    * @Author: mryunqi
    * @Description: 普通用户获取商品列表
    * @DateTime: 2023/4/22 0:56
    * @Params: int page 页码
    * @Params: int size 页数据量
    * @Return ResponseResult<Page<Commodity>>
    */
    @ApiCheck
    @GetMapping("/user/getCommodityList")
    public ResponseResult<Page<Commodity>> getCommodityList(@RequestParam(value = "page",defaultValue = "1") int page,
                                                            @RequestParam(value = "size",defaultValue = "20") int size)
            throws UnauthorizedException {
        QueryWrapper<Commodity> queryWrap = new QueryWrapper<>();
        queryWrap.eq("hide",0);
        return ResponseResult.ok(commodityService.getCommodityList(page, size,queryWrap));
    }
}
